package com.ywu.boot.configuration;


import com.ywu.boot.interceptor.ContextBuilderInterceptor;
import com.ywu.boot.interceptor.ContextBuilderInterface;
import com.ywu.boot.interceptor.TraceLogInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

/**
 * @ClassName TraceLogConfiguration
 * @Description TODO
 * @Author GroundDemo
 * @Date 2024/3/16 12:25
 * @Version 1.0
 **/
@Configuration
public class TraceLogConfiguration implements WebMvcConfigurer {
    @Autowired
    private List<ContextBuilderInterface> contextBuilder;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        ContextBuilderInterceptor contextBuilderInterceptor = new ContextBuilderInterceptor(this.contextBuilder);
        registry.addInterceptor(contextBuilderInterceptor).addPathPatterns("/**");
        TraceLogInterceptor traceLogFilter = new TraceLogInterceptor();
        registry.addInterceptor(traceLogFilter)
                // 添加拦截路径模式
                .addPathPatterns("/**"); // 拦截所有请求
    }
}
